#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

. /etc/init.d/functions

if [[ -f /etc/lab/lab-functions ]]; then
    . /etc/lab/lab-functions
fi


clear

[[ -f '/proc/cmdline' ]] && cmdline=$(cat /proc/cmdline)
app=$(grep APP /etc/lab/lab.conf)
app=${app#*=}

#if eth parameter is specified in kernel cmdline, override the system config
if strstr "$cmdline" eth; then
    eth=${cmdline#*eth=}

    OLDIFS=$IFS
    IFS=$'\n'
    arr=( $(echo $eth | awk -F':' '{ for(i=1; i<=NF; i++) { print $i } }') )
    IFS=$OLDIFS
    
    /sbin/ifconfig ${arr[0]} ${arr[1]} up
    route add -net default gw ${arr[2]}
    [[ ${arr[3]} ]] && echo nameserver ${arr[3]} > /etc/resolv.conf
    [[ ${arr[4]} ]] && echo nameserver ${arr[4]} >> /etc/resolv.conf
    [[ ${arr[5]} ]] && echo nameserver ${arr[5]} >> /etc/resolv.conf

    ip=${arr[1]%/*}
else
    tmp=$(ifconfig | grep "inet addr" | grep -v "127.0.0.1")
    tmp2=${tmp#*inet addr:}
    ip=${tmp2%% *}
fi

#create /etc/issue file to notify user how to access the box
create_issue $ip
